const { AsyncParallelBailHook } = require('tapable')

let hook = new AsyncParallelBailHook(['name'])

console.time('time')
hook.tapAsync('fn1', function (name, callback) {
    setTimeout(()=>{
        console.log('fn1--->', name)
        callback()
    }, 1000)
})
hook.tapAsync('fn2', function (name, callback) {
    setTimeout(()=>{
        console.log('fn2--->', name)
        callback('error') // 当callback中有携带参数返回，就会先执行回调内容
    }, 2000)
})

hook.tapAsync('fn3', function (name, callback) {
    setTimeout(()=>{
        console.log('fn3--->', name)
        callback()
    }, 3000)
})

hook.callAsync('tapAsync', function () {
    console.log('最后一个回调执行了')
    console.timeEnd('time')
})
